@isTest
private class QueryDataRESTTest {
    static testMethod void testMethod1() {
        
         User u2= new User( Alias = 'samLdc2', 
                     Email = 'ldc2@test.com.maike',
                     Emailencodingkey = 'UTF-8', 
                     Lastname = '用户2', 
                     Languagelocalekey = 'en_US',
                     Localesidkey = 'en_US', 
                     Profileid = [select Id from Profile where name like '%工程师%' limit 1].Id , 
                     Country = 'United States',
                     IsActive = true,
                     SubCompany__c='四川省迈克实业有限公司',
                     UserDepartment__c='客户服务中心(工程部)',
                     Timezonesidkey = 'America/Los_Angeles', 
                     EmployeeNumber = '121234',
                     CompanyName = 'Y-MKSY',
                     FederationIdentifier = '123452',
                     Username = 'Matldc2@test.com.maike',
                     ResponseCode__c = 'TTTT' );
         insert u2;
        	 //产品结构
        ProductStructure__c ps1=new ProductStructure__c();
        ps1.Name='仪器';
        ps1.Classify1__c='生化';
        ps1.Classify2__c='生化-设备';
        ps1.Classify3__c='仪器';
        insert ps1;
        Brand__c brand = new Brand__c(
        	BrandShortName__c = '四川迈克'
        );
        insert brand;
          //产品
        Product__c p1=TestUtils.createProduct();
        p1.Name='仪器';
        p1.Category0__c = '仪器';
        p1.Model__c='Model1228';
        p1.ProductStructure__c=ps1.Id;
        p1.CRMBrand__c = brand.Id;
        p1.RecordTypeId =  Utils.getRecordTypeIdByDevNameAndObjName('NCProduct','Product__c');
        insert p1;

         Account acc=new Account();
        acc.Name='Test1229J';
        acc.Level__c = '一级医院';
        insert acc;
        Dealer__c d = new Dealer__c(
        	Only__c='Dealer__c'
        );
        insert d;


        Case cas=new Case();
        cas.AccountId=acc.Id;
        insert cas;

        WorkOrder__c wo=new WorkOrder__c();
        wo.Case__c=cas.Id;
        wo.Account__c=acc.Id;
        wo.Status__c='处理中';
        wo.ManufactureInfo__c=p1.Id;
        wo.Technician__c = u2.Id;
        wo.recordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('ServiceOrder','WorkOrder__c');
        insert wo;

        WorkOrder__c wo1 = [select Id,Technician__c,Technician__r.ExuserCode__c from WorkOrder__c where Id =:wo.Id ];
        System.debug('QueryDataRESTTest==>'+wo1.Technician__r.ExuserCode__c);
		Map<String,String>pm = new Map<String,String>();
		pm.put('workno','1234');
		QueryDataREST.QueryBean qb = new QueryDataREST.QueryBean();
		qb.method ='api_getWorkOrder';
		qb.params = pm;
		System.debug(QueryDataREST.dopost(qb));


        // Account acc = TestUtils.createAccount();
        // acc.Level__c = '三级甲等';
        // acc.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('Dealer', 'Account');

        // insert acc;     

        //业务机会1
        Opportunity opp = TestUtils.createOpportunity();
        opp.AccountId = acc.Id;
        insert opp;

        Id pRT = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');

        Product__c p  = TestUtils.createInst();
        p.Name = '测试仪器';
        p.RecordTypeId = pRT;
        p.Category0__c  = '仪器';
        p.ProductName__c = '测试仪器';
        insert p ;

        Contract__c con = new Contract__c();
        con.Account__c = acc.Id;
        con.Opportunity__c = opp.Id;
        con.Status__c  = '已生效';
        con.Corpcode__c = 'MKSY';
        con.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('TerminalContract', 'Contract__c');
        insert con;

        ContractProduct__c cp = new ContractProduct__c();
        cp.Contract__c = con.Id;
        cp.Product__c =p.Id  ;
        cp.Quantity__c = 1;
        cp.SalesPrice__c = 1; 

        insert cp ;


        Map<String,String>pm1 = new Map<String,String>();
        pm1.put('contractId',con.Id );
        QueryDataREST.QueryBean qb1 = new QueryDataREST.QueryBean();
        qb1.method ='api_getContractInfo';
        qb1.params = pm1;
        System.debug(QueryDataREST.dopost(qb1));


    }
}